package com.ccovo.controller;

import com.ccovo.domain.R;
import com.ccovo.domain.dto.UserDTO.UserAddDTO;
import com.ccovo.domain.dto.UserDTO.UserEditDTO;
import com.ccovo.domain.query.UserQuery;
import com.ccovo.service.IUserService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/user/")
public class UserController {

    private final IUserService userService;

    /**
     * 新增用户信息
     */
    @ApiOperation(value = "新增用户信息")
    @PostMapping("/save")
    public R<?> save(@RequestBody UserAddDTO addDTO) {
        return R.ok(userService.saveUser(addDTO));
    }

    /**
     * 单个查询用户信息
     */
    @ApiOperation(value = "单个查询用户信息")
    @GetMapping("/selectById/{id}")
    public R<?> selectById(@PathVariable Long id) {
        return R.ok(userService.selectById(id));
    }

    /**
     * 修改当前用户信息
     */
    @ApiOperation(value = "修改当前用户信息")
    @PutMapping("/update")
    public R<?> update(@RequestBody UserEditDTO editDTO) {
        return R.ok(userService.updateUserById(editDTO));
    }

    /**
     * 单个删除用户信息
     */
    @ApiOperation(value = "单个删除用户信息")
    @DeleteMapping("/delete/{id}")
    public R<?> delete(@PathVariable Long id) {
        return R.ok(userService.deleteById(id));
    }

    /**
     * 分页查询用户信息
     */
    @ApiOperation(value = "分页查询用户信息")
    @GetMapping("/selectPage")
    public R<?> selectPage(UserQuery userQuery) {
        return R.ok(userService.selectPage(userQuery));
    }



}
